<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>测试</title>
</head>

<body>

</body>
<script>
  let timediif = new Date().getTime();
  let count = 1;
  const interval = setInterval(() => {
    fetch("/api/myName", {
        method: "GET",
        cache: 'no-cache', // *default, no-cache, reload, force-cache, only-if-cached
        credentials: 'same-origin', // include, same-origin, *omit
        headers: {
          'user-agent': 'Mozilla/4.0 MDN Example',
          'content-type': 'application/json'
        },
        mode: 'cors', // no-cors, cors, *same-origin
        redirect: 'follow', // manual, *follow, error
        referrer: 'no-referrer', // *client, no-referrer
      }).then((res) => {
        return res.text();
      })
      .then((text) => {
        let now = new Date().getTime();
        console.log('请求间隔时间毫秒:', now - timediif, text);
        timediif = now;
        count++;
        if (count > 100) {
          clearInterval(interval);
        }
      }).catch((e) => {
        console.log('err', e);
        clearInterval(interval);
      });
  }, 100);
</script>

</html>